import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'

import 'element-plus/dist/index.css';
import "element-plus/theme-chalk/el-message.css";
import "element-plus/theme-chalk/el-message-box.css";
import "@/router/dynamicAddRouter";
import "default-passive-events";
import "nprogress/nprogress.css";

import { useUserStore } from "@/stores/admin";
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';//引入pinia持久化插件
import { i18n } from "@/I18n";

const pinia = createPinia();
const app = createApp(App);

pinia.use(piniaPluginPersistedstate);//持久化插件注册在pinia
app.use(pinia);//全局注册pinia
app.use(router);
app.use(i18n);

/**
 * 自定义指令
 * 根据登录角色权限隐藏操作按钮
 * 自定义一个全局权限指令 使用directive方法，可以在任意组件中被使用；
 * 使用生命周期钩子函数（节点，绑定的值）
 */
app.directive('permission', {
    mounted(el, binding) {
        const store = useUserStore();
        let val = binding.value;
        var permissionList = store.permissionList || [];
        if (-1 === permissionList.indexOf(val)) {
            el?.remove();
        }
    }
});

app.mount('#app');
